/**
 * Project Name:template-web
 * File Name   :RegexUtil.java
 * Package Name:org.cn.template.component.utils
 * Date:2015年9月27日下午4:15:01
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
*/

package org.cn.template.component.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ClassName:RegexUtil <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason	:TODO ADD REASON. <br/>
 * Date     :2015年9月27日 下午4:15:01 <br/>
 * @author  :http://my.oschina.net/httpssl
 * @email   :491835898@QQ.COM
 * @since   :JDK 1.7
 * @see 	 
 */
public class RegexUtil
{

	public static final String V_INTEGER = "^-?[1-9]\\d*$";
	public static final String V_EMAIL = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
	public static final String V_URL = "^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$";
	public static final String V_CHINESE = "^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$";
	public static final String V_ASCII = "^[\\x00-\\xFF]+$";
	public static final String V_ZIPCODE = "^\\d{6}$";
	public static final String V_IP4 = "^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$";
	public static final String V_PICTURE = "(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$";
	public static final String V_RAR = "(.*)\\.(rar|zip|7zip|tgz)$";
	public static final String V_PASSWORD_REG = "[A-Za-z]+[0-9]";

	public RegexUtil() {
	}
	
	public static boolean Email(String value) {
		return match(V_EMAIL,value);
	}
 
	private static boolean match(String regex, String str) {
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}
}
